import { get } from "jquery"
//import * as types from './Interfaces.json'

export const asynclogin = function () {
    return new Promise((resolve, reject) => {
        get("/a.json").then(response => {
            if (response.error == 0) {
                console.log(response.userName)
                resolve(response.userName)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

export const session = function () {
    return new Promise((resolve, reject) => {
        get("/a.json").then(response => {
            if (response.error == 0) {
                console.log(response.userName)
                resolve(response.userName)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

export const allUser = function () {
    return new Promise((resolve, reject) => {
        get("/a.json").then(response => {
            if (response.error == 0) {
                resolve(response.allUser)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

export const getallcourse = function () {
    return new Promise((resolve, reject) => {
        get("/a.json").then(response => {
            if (response.error == 0) {
                resolve(response.message)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}



export const packagekey = function () {
    return new Promise((resolve, reject) => {
        get("/a.json").then(response => {
            if (response.error == 0) {
                resolve(response.packagekey)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

export const asyncgetCourseAndLessionsByCourseID = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.getCourseAndLessionsByCourseID)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

export const asyncuploadAccess = function () {
    return new Promise((resolve, reject) => {
        get("/a.json").then(response => {
            if (response.error == 0) {
                resolve(response.uploadAccess)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 添加course
export const asyncuploadCourse = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 删除course
export const asyncdeleteCourse = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 更新course
export const asyncupdateCourse = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 添加lession
export const asyncuploadLession = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.uploadLession)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 更新lession
export const asyncupdateLession = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.updateLession)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}
// 删除lession
export const asyncdeleteLession = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.deleteLession)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 添加代理商
export const asyncnewAgent = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.agentRegist)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}


// 添加package
export const asyncnewPackege = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.newPackege)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 添加AgentKey
export const asyncaddAgentKey = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.addAgentKey)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 添加AgentKey
export const asyncaddPackegeKey = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.addPackegeKey)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 添加addPackege
export const asyncaddPackege = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.addPackege)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 获取package
export const asyncgetAllPackege = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.getAllPackege)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

export const asyncgetCourseByPackegeID = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.message)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

export const asyncgetUserByUser = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.userName)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

export const asyncgetUserCourseInfo = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.message)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 获取代理商课程包
export const asyncgetAgentCoursePak = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.getInvite)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 删除代理商课程包
export const asyncdeleteAgebtKeyByID = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.getInvite)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

//  删除课程包的课程
export const asyncdeletePackegeByID = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.getInvite)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 删除课程包
export const asyncdeletePackegeKeyByID = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.getInvite)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 修改用户
export const asyncupdateUser = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.getInvite)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}


// 删除用户
export const asyncdeleteUserByID = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.getInvite)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}


// 修改课程包
export const asyncupdatePackegeKey = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.getInvite)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}



export const asyncvideoQuestion = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.question)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}


// 添加视频问题
export const asyncuploadQuestion = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.question)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}


// 修改视屏问题
export const asyncupdateQuestion = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.question)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 删除视频问题

export const asyncdeleteQuestion = function (data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.question)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 管理员获取视频
export const asyncgetVideoPermissionByID = function(data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.videoList)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 提交答案 
export const asynccheckQuestion = function(data) {
    return new Promise((resolve, reject) => {
        get("/a.json", data).then(response => {
            if (response.error == 0) {
                resolve(response.videoList)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}